package com.yanqu.road.entity.activity.guagifts;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.utils.date.DateHelper;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@FieldTypeAnnotation(tableName = "t_u_gua", desc = "孤寡献礼玩家数据")
public class UserGuaData extends DataObject {
    @FieldTypeAnnotation(select = true, update = true, desc = "活动id")
    private int activityId;
    @FieldTypeAnnotation(select = true, update = true, desc = "用户id")
    private long userId;
    @FieldTypeAnnotation(desc = "贵族值,榜单值")
    private int nobleValue;
    @FieldTypeAnnotation(desc = "孤寡值,榜单值")
    private int guaValue;
    @FieldTypeAnnotation(desc = "送礼成就值")
    private int sendNobleCount;
    @FieldTypeAnnotation(desc = "收礼每日累计")
    private Map<Integer,Integer> dayCountMap = new HashMap<>();
    @FieldTypeAnnotation(desc = "最近一次收花时间")
    private long lastGetTime;
    @FieldTypeAnnotation(desc = "已经领了的广播奖励")
    private Set<Long> getBroadcastList = new HashSet<>();
    @FieldTypeAnnotation(desc = "已经收到的广播奖励")
    private Set<Long> watchBroadcastList = new HashSet<>();
    @FieldTypeAnnotation(desc = "最近一次收到广播的时间")
    private long lastWatchTime;

    public UserGuaData(int activityId, long userId) {
        this.activityId = activityId;
        this.userId = userId;
        setInsertOption();
    }

    public UserGuaData() {
    }

    public int getActivityId() {
        return activityId;
    }
    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setOp(DataStatus.Update);
        }
    }

    public long getUserId() {
        return userId;
    }
    public void setUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            setOp(DataStatus.Update);
        }
    }

    public int getNobleValue() {
        return nobleValue;
    }
    public void setNobleValue(int nobleValue) {
        if (this.nobleValue != nobleValue) {
            this.nobleValue = nobleValue;
            setOp(DataStatus.Update);
        }
    }

    public int getSendNobleCount() {
        return sendNobleCount;
    }
    public void setSendNobleCount(int sendNobleCount) {
        if (this.sendNobleCount != sendNobleCount) {
            this.sendNobleCount = sendNobleCount;
            setOp(DataStatus.Update);
        }
    }


    public long getLastGetTime() {
        return lastGetTime;
    }
    public void setLastGetTime(long lastGetTime) {
        if (this.lastGetTime != lastGetTime) {
            this.lastGetTime = lastGetTime;
            setOp(DataStatus.Update);
        }
    }

    public Set<Long> getGetBroadcastList() {
        return getBroadcastList;
    }
    public void setGetBroadcastList(HashSet<Long> getBroadcastList) {
        if (null == getBroadcastList){
            return;
        }
        if (this.getBroadcastList == null || !this.getBroadcastList.equals(getBroadcastList)) {
            this.getBroadcastList = getBroadcastList;
            setOp(DataStatus.Update);
        }
    }

    public void addBroadcastId(long broadcastId){
        this.getBroadcastList.add(broadcastId);
        setUpdateOption();
    }

    public Set<Long> getWatchBroadcastList() {
        return watchBroadcastList;
    }

    public void setWatchBroadcastList(HashSet<Long> watchBroadcastList) {
        this.watchBroadcastList = watchBroadcastList;
    }

    public void addWatchBroadcastId(long broadcastId){
        this.watchBroadcastList.add(broadcastId);
        this.setLastWatchTime(DateHelper.getCurrentTime());
        setUpdateOption();
    }

    public boolean wasGetBroadcast(long broadcastId){
        return this.getBroadcastList.contains(broadcastId);
    }

    public boolean wasWatchBroadcast(long broadcastId){
        return this.watchBroadcastList.contains(broadcastId);
    }

    public long getLastWatchTime() {
        return lastWatchTime;
    }

    public void setLastWatchTime(long lastWatchTime) {
        if (this.lastWatchTime != lastWatchTime) {
            this.lastWatchTime = lastWatchTime;
            setOp(DataStatus.Update);
        }
    }

    public int getGuaValue() {
        return guaValue;
    }

    public void setGuaValue(int guaValue) {
        this.guaValue = guaValue;
        setUpdateOption();
    }

    public Map<Integer, Integer> getDayCountMap() {
        return dayCountMap;
    }

    public void setDayCountMap(Map<Integer, Integer> dayCountMap) {
        this.dayCountMap = dayCountMap;
        setUpdateOption();
    }

    public void addDayCount(int giftId, int count){
        Integer totalCount = this.dayCountMap.getOrDefault(giftId, 0);
        totalCount+=count;
        this.dayCountMap.put(giftId, totalCount);
        setUpdateOption();
    }
}
